class Solution {
    bool getInvalidInput = false;  //获取错误信息
public:
    double myPow(double x, int n) {
        if(0 == n)  return 1.0;
        if(abs(x) < 0.000001 && (n < 0)){
            getInvalidInput = true;
            return 0.0;  //错误情况：对0取倒数无意义
        }
        double result = 1.0;

        unsigned int absn = abs(n);
       
        //快速幂
        double res = 1.0;
        while(absn > 1){
            if(absn % 2)  res *= x;
            x = x*x;
            absn /= 2;
        }
        result = res * x;

        if(n < 0)  result = 1.0 / result;

        return result;
    }
};